package mdb

import (
	"database/sql"
	"fmt"
	"log"
	"strings"

	_ "github.com/go-sql-driver/mysql"
)

const (
	userName = "jjj"
	passWord = "a13509355545"
	ip       = "39.108.90.170"
	port     = "3306"
	dbName   = "jjj"
)

var DB *sql.DB

func ConnectDB() *sql.DB {
	path := strings.Join([]string{userName, ":", passWord, "@tcp(", ip, ":", port, ")/", dbName, "?charset=utf8"}, "")

	DB, err := sql.Open("mysql", path)
	if err != nil {
		log.Println("# Failed to connect to database: ", err)
		return nil
	}
	fmt.Println("# Successfully connected to database.")
	return DB
}


func DisconnectDB(DB *sql.DB) bool{
	err := DB.Close()
	if err != nil{
		log.Println("Failed to disconnect database: ",err)
		return false
	}
	return true
}
